package edu.neusoft.yuejian_09.model;


import java.util.List;

import edu.neusoft.yuejian_09.base.Constant;
import edu.neusoft.yuejian_09.base.RetrofitBaseModel;
import edu.neusoft.yuejian_09.base.RetrofitListener;
import edu.neusoft.yuejian_09.bean.Activities;
import edu.neusoft.yuejian_09.bean.Contest;
import edu.neusoft.yuejian_09.bean.EnterActBean;
import edu.neusoft.yuejian_09.bean.EnterTrainBean;
import edu.neusoft.yuejian_09.bean.Master;
import edu.neusoft.yuejian_09.bean.Show;
import edu.neusoft.yuejian_09.bean.User;
import retrofit2.Call;
import edu.neusoft.yuejian_09.service.UserService;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

import static edu.neusoft.yuejian_09.base.Constant.BASE_URL;

/**
 * Created by Administrator on 2017/9/28.
 */

public class UserModel  extends RetrofitBaseModel {
    public UserService userService;
    public UserModel(){
        this.userService=retrofit.create(UserService.class);
    }

    private int flag=1;

    public void Login(String username, String password, final RetrofitListener listener){
        UserService userService=retrofit.create(UserService.class);
        Call call=userService.userLogin(username,password);
        Callback<User> callback=new Callback<User>(){
            @Override
            public void onResponse(Call<User> call, Response<User> response){
                User user = response.body();
                listener.onSuccess(user,flag);

            }
            @Override
            public  void onFailure(Call<User> call,Throwable t){
                t.printStackTrace();
                listener.onFail();
            }
        };
        call.enqueue(callback);
    }

    //获取用户详情
    public void getUserById(int user_id, final RetrofitListener listener){
        Call call=userService.getUserById(user_id);
        bindCallback(call,listener, Constant.USERBYID);
    }


    public Call reg(String str_user,String str_password, String user_phone,String str_comment){
        UserService userService=retrofit.create(UserService.class);
        return userService.userRegister(str_user,str_password,user_phone,str_comment);
    }
    //获取用户信息
    public Call<User> getUserInfo(int user_id) {
        UserService userService = retrofit.create(UserService.class);
        return userService.getUserInfo(user_id);
    }

    public Call<User> edituser(int user_id) {
        UserService userService = retrofit.create(UserService.class);
        return userService.edituser(user_id);
    }

    public Call<User> updateuser(int user_id, String user_name, String user_password, String user_phone) {
        UserService userService = retrofit.create(UserService.class);
        return userService.updateuser(user_id, user_name, user_password, user_phone);
    }

    //查看我的活动订单列表
    public Call<List<EnterActBean>> getMyActOrderlist(int user_id) {
        UserService userService = retrofit.create(UserService.class);
        return userService.getMyActOrderlist(user_id);
    }

    //查看我的培训订单列表
    public Call<List<EnterTrainBean>> getMyTrainOrderlist(int user_id) {
        UserService userService = retrofit.create(UserService.class);
        return userService.getMyTrainOrderlist(user_id);
    }

    public Call<List<Show>> getMypostlist(int user_id) {
        UserService userService = retrofit.create(UserService.class);
        return userService.getMypostlist(user_id);
    }

    //查看我关注的用户
    public Call<List<User>> getMyCollectUsers(int user_id, String flag) {
        UserService userService = retrofit.create(UserService.class);
        return userService.getMyCollectUsers(user_id,flag);
    }


    //查看我关注的比赛
    public Call<List<Contest>> getMyCollectMatch(int user_id, String flag) {
        UserService userService = retrofit.create(UserService.class);
        return userService.getMyCollectMatch(user_id,flag);
    }

    //查看我关注的大师
    public Call<List<Master>> getMyCollectMaster(int user_id, String flag) {
        UserService userService = retrofit.create(UserService.class);
        return userService.getMyCollectMaster(user_id,flag);
    }


    //查看我关注的活动
    public Call<List<Activities>> getMyCollectActivity(int user_id, String flag) {
        UserService userService = retrofit.create(UserService.class);
        return userService.getMyCollectActivity(user_id,flag);
    }

}
